package com.liziba.unsafe;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * <p>
 *
 * </p>
 *
 * @Author: Liziba
 * @Date: 2021/5/23 13:27
 */
public class UnsafeFactory {

    /**
     * 获取Unsafe
     *
     * @return
     */
    public static final Unsafe getUnsafe() {

        Unsafe unsafe = null;
        try {
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
            theUnsafe.setAccessible(true);
            unsafe = (Unsafe) theUnsafe.get(null);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return unsafe;
    }


    public static void main(String[] args) {

        Unsafe unsafe = getUnsafe();
        System.out.println(unsafe);
    }

}
